<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: group_prices.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

defined('_VALID_XTC') or die('Direct Access to this location is not allowed.');
require_once (DIR_FS_INC.'inc.get_tax_rate.php');
require_once (DIR_FS_INC.'inc.get_tax_class_id.php');

require (DIR_FS_CATALOG.DIR_WS_CLASSES.'class.price.php');

$price = new price(DEFAULT_CURRENCY, $_SESSION['customers_status']['customers_status_id'], $db);

$products_price_brutto = round($pInfo->products_price * ((100 + get_tax_rate($pInfo->products_tax_class_id)) / 100), PRICE_PRECISION);
?>
<table width="100%" class="tablePrice">
	<tr>
		<td id="productsPrice" class="main" align="right"><?php echo TEXT_PRODUCTS_PRICE; ?></td>
		<td id="productsPriceInput" class="main">
			<?php 
				if (PRICE_IS_BRUTTO == 'true')
					echo TEXT_BRUTTO.draw_input_field('products_price', $products_price_brutto, 'size="10" style="text-align:right"').$price->currencies[$price->actualCurr]['symbol_right'].'&nbsp;-&nbsp;'.TEXT_NETTO.'<b>'.$price->format($pInfo->products_price, false).'</b> '.$price->currencies[$price->actualCurr]['symbol_right'];
				else
					echo TEXT_NETTO.draw_input_field('products_price', $price->format($pInfo->products_price, false), 'size="10" style="text-align:right"').$price->currencies[$price->actualCurr]['symbol_right'].'&nbsp;-&nbsp;'.TEXT_BRUTTO.'<b>'.$products_price_brutto.'</b> '.$price->currencies[$price->actualCurr]['symbol_right'];
			?>
		</td>
	</tr>
	<tr>
		<td id="productsPrice" class="main" align="right"><?php echo TEXT_PRODUCTS_TAX_CLASS; ?></td>
		<td id="productsPriceInput" class="main">
			<?php
				if ($pInfo->products_tax_class_id == '')
				foreach ($tax_class_array AS $tax_class_entry) {
					if (preg_match("/standard/i", $tax_class_entry['text']))
						$pInfo->products_tax_class_id = $tax_class_entry['id'];
				}
				echo draw_pull_down_menu('products_tax_class_id', $tax_class_array, $pInfo->products_tax_class_id); 
			?>
		</td>
	</tr>
	<tr>
		<td id="productsPrice" class="main" align="right"><?php echo TEXT_PRODUCTS_EXTRA_SHIPPING; ?></td>
		<td id="productsPriceInput" class="main"><?php echo draw_input_field('products_shipping_costs', ($pInfo->products_shipping_costs != '0.0000' ? $pInfo->products_shipping_costs:'')); ?></td>
	</tr>
	<tr>
		<td id="productsPrice" class="main" align="right"><?php echo TEXT_PRODUCTS_DISCOUNT_ALLOWED; ?></td>
		<td id="productsPriceInput" class="main"><?php echo draw_input_field('products_discount_allowed', ($pInfo->products_discount_allowed !='0.00' ? $pInfo->products_discount_allowed:'')); ?></td>
	</tr>
</table><br />

<div class="header">Sonderpreis <?php echo get_help(26, 'Sonderangebot'); ?></div>
<table width="100%">
	<?php
		$groups = get_customers_statuses();
		foreach($groups AS $group) {
			$check_col = $db->db_query("SHOW COLUMNS FROM ".TABLE_SPECIALS." LIKE 'specials_price_".$group['id']."'");
			
			if($check_col->_numOfRows) {
				$Special = $db->db_query("SELECT 	
												specials_id, 
												specials_price_".$group['id'].",
												specials_quantity,
												expires_date,
												status
											FROM 
												".TABLE_SPECIALS." 
											WHERE 
												products_id = '".$pInfo->products_id."' ");

				$sprice = $Special->fields['specials_price_'.$group['id']];								
				
			} else {
				$db->db_query("ALTER TABLE ".TABLE_SPECIALS." ADD specials_price_".$group['id']." DECIMAL(15,4) NOT NULL;");
				$sprice = '';
			}
			
			echo '	<tr>';
			echo '		<td class="main" align="right">'.$group['text'].'</td>';
			echo '		<td class="main">'.getSpecialPriceField($sprice, $group['id'], $pInfo->products_tax_class_id).'</td>';
			echo '	</tr>';
		}
	?>
	<tr>
		<td class="main" align="right">Ablaufdatum:</td>
		<td class="main">
			<input type="text" name="expires_date" class="special_date" value="<?php echo ($Special->fields['expires_date'] != '0000-00-00 00:00:00' ? $Special->fields['expires_date'] : ''); ?>" />
			<script type="text/javascript">
				$(function(){
					$('.special_date').datetimepicker({
						minDate: new Date(<?php echo date('Y').','.date('m').'-1,'.date('d'); ?>),
						buttonImage: "includes/javascript/ui/images/calendar.png",
						showOn: "button",
						dateFormat : 'yy-mm-dd',
						showSecond: true,
						timeFormat: 'hh:mm:ss',
						stepMinute: 10,
						stepSecond: 10
					});
				});
			</script>
		</td>
	</tr>
	<tr>
		<td class="main" align="right">
			Anzahl:
		</td>
		<td class="main">
			<?php echo draw_input_field('specials_quantity', ($Special->fields['specials_quantity'] !=0 ? $Special->fields['specials_quantity'] : ''), 'size="5" style="text-align:center"');?>
		</td>
	</tr>
	<?php if(!empty($Special->fields['specials_id'])) { ?>
	<tr>
		<td class="main" align="right">
			Aktiv?
		</td>
		<td class="main">
			<?php echo draw_radio_field_jq('specials_status', array(1 => array('1', YES), 0 => array('0', NO)), $Special->fields['status'] || !isset($_GET['pID']) ? '1' : '0'); ?>
		</td>
	</tr>
	<tr>
		<td class="main" align="right">
			Angebot beenden?
		</td>
		<td class="main">
			<input type="checkbox" name="del_special" value="yes" />
		</td>
	</tr>
	<?php } ?>
</table>

<br />
<div class="header">Staffelpreise</div>
<div id="staffelpreise">
<?php
	$text_price = STAFFEL_NETTO;
	if(PRICE_IS_BRUTTO == 'true')
		$text_price = STAFFEL_BRUTTO;
	
	$i = 0;
	$group_values = $db->db_query("SELECT
				                       customers_status_image,
				                       customers_status_id,
				                       customers_status_name
				                   FROM
				                       ".TABLE_CUSTOMERS_STATUS."
				                   WHERE
				                       language_id = '".$_SESSION['languages_id']."' AND customers_status_id != '0'");
	while(!$group_values->EOF) {
		$i++;
		$group_data[$i] = array('STATUS_NAME' => $group_values->fields['customers_status_name'],
								'STATUS_IMAGE' => $group_values->fields['customers_status_image'],
								'STATUS_ID' => $group_values->fields['customers_status_id']);
		$group_values->MoveNext();
	}
	for($col = 0, $n = sizeof($group_data); $col < $n +1; $col ++) {
		$staffel_data_array = array();
		if ($col != 0) {
			if(PRICE_IS_BRUTTO == 'true') {
				$products_price = (get_group_price($group_data[$col]['STATUS_ID'], $pInfo->products_id)*get_tax_rate(get_tax_class_id($pInfo->products_id))/100)+get_group_price($group_data[$col]['STATUS_ID'], $pInfo->products_id);
			} else
				$products_price = get_group_price($group_data[$col]['STATUS_ID'], $pInfo->products_id);
	
			$staffel_values = $db->db_query("SELECT
		                                         products_id,
		                                         quantity,
		                                         personal_offer
		                                     FROM
		                                     	".TABLE_PERSONAL_OFFERS_BY.$group_data[$col]['STATUS_ID']."
		                                     WHERE
		                                         products_id = '".$pInfo->products_id."' AND quantity != 1
		                                     ORDER BY quantity ASC");
			while(!$staffel_values->EOF) {
				if (PRICE_IS_BRUTTO == 'true')
					$products_staffel_price = ($staffel_values->fields['personal_offer']*get_tax_rate(get_tax_class_id($pInfo->products_id))/100)+$staffel_values->fields['personal_offer'];
				else
					$products_staffel_price = $staffel_values->fields['personal_offer'];
				$staffel_values->MoveNext();
			}
	
			$li_id .= '<li><a href="#'.get_url_friendly_text($group_data[$col]['STATUS_NAME']).'" onclick="return false">'.$group_data[$col]['STATUS_NAME'].'</a></li>';
			$div_id .= '<div id="'.get_url_friendly_text($group_data[$col]['STATUS_NAME']).'">
							<fieldset class="fieldset">
								<div>
									<div class="titlePrice">'.STAFFEL_GROUP_BASE_PRICE.'</div>
									<div>'.draw_input_field('products_price_'.$group_data[$col]['STATUS_ID'], round($products_price, PRICE_PRECISION),' id=products_price_'.$group_data[$col]['STATUS_ID'].' size="8" style="width:50px"').' ('.$text_price.')</div>
								</div>
								<div class="fieldsetInnert">
									<div id="staffel_value_'.$group_data[$col]['STATUS_ID'].'" name="staffel_value_'.$group_data[$col]['STATUS_ID'].'"></div>
									<div class="clear" id="staffel_add_'.$group_data[$col]['STATUS_ID'].'" name="staffel_add_'.$group_data[$col]['STATUS_ID'].'"></div>
								</div>
							</fieldset>
						</div>';
			}
		}
	?>
	<ul><?php echo $li_id ?></ul>
	<?php echo $div_id ?>
</div>
<?php
function getSpecialPriceField($sprice = '', $cg_id, $tax) {
	global $price;
	
	if(!empty($sprice) && $sprice !='0') {
		$sprice_brutto = round($sprice * ((100 + get_tax_rate($tax)) / 100), 2);
		
		if(PRICE_IS_BRUTTO == 'true') {
			
			return TEXT_BRUTTO.draw_input_field('products_specials_price_'.$cg_id, $sprice_brutto, 'size="10" style="text-align:right;color:#b20000"').$price->currencies[$price->actualCurr]['symbol_right'].'&nbsp;-&nbsp;'.TEXT_NETTO.'<b>'.$price->format($sprice, false).'</b> '.$price->currencies[$price->actualCurr]['symbol_right'];
		} else {
			return TEXT_NETTO.draw_input_field('products_specials_price_'.$cg_id, $price->format($sprice, false), 'size="10" style="text-align:right;color:#b20000"').$price->currencies[$price->actualCurr]['symbol_right'].'&nbsp;-&nbsp;'.TEXT_BRUTTO.'<b>'.$sprice_brutto.'</b> '.$price->currencies[$price->actualCurr]['symbol_right'];
		}
	} else
		return draw_input_field('products_specials_price_'.$cg_id, '', 'size="10"');
}